package model;

import java.awt.Color;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.util.ArrayList;

public class StackPredict<E> extends AdapterStack<E> implements Prediction<E>{
	
	private ArrayList<Integer> yCo; 
	private boolean predictPressed = false;

	public boolean predictAdd(int guess) {
		if(guess == S.size()+1){
			return true;
		}
		else{
			return false;
		}
	}

	@Override
	public boolean predictRemove(int guess) {
		if(guess == (S.size()-1)){
			return true;
		}
		else{
		return false;
		}
	}
	public void setPressed(boolean b){
		predictPressed = b;
	}
	
	
	public ArrayList<Integer> getYCo(){
		return yCo;
	}

	public void paint(Graphics g) {
		
	     g.setFont(new Font("",0,15));
		 g.drawString("Stack Mode", 10, 20);
		
		if(!S.isEmpty()){
			
			yCo  = new ArrayList<Integer>();	
			 g.setFont(new Font("",0,50));
		     FontMetrics fm = null;
		     fm = g.getFontMetrics();
		     
		     int x = 400;
		     int y = 550;
		     int h = 60;
		     int w = 60;
		     
		     if(predictPressed == true){
		    	 //Draws opaque box for potential addition prediction
		    	 y = 620;
		    	 yCo.add(y);
		    	 g.setColor(new Color(0,0,0,100));
		    	 g.drawRect(x,y,w,h);
		    	 y= y-h-10;
		     }
		     g.setColor(new Color(0,0,0,200));

		     	
			     for(int i=size(); i != 0; i--){
			         yCo.add(y); 
			    	 String s = (String) S.get(i-1);
			         g.drawRect(x, y, w, h);
			         g.drawString(s,(((w - fm.charWidth(s.charAt(0)))/2)+x), (y + 47 ));
			         y = y - h -10;

			        
			     }
			  if(predictPressed==true){
				  yCo.add(y);
				 //Draws opaque box for potential addition prediction
				 g.setColor(new Color(0,0,0,100));
				 g.drawRect(x, y, w, h);			  
			  }
		predictPressed =false;	  
		}	
	
	}

}
